import cgi
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

from google.appengine.api import users
from models.root_models import rcAdmin

class AuthHandler(webapp.RequestHandler):
  def get(self, direction):
    if(direction == 'out'): # User is logging out
      self.redirect(users.create_logout_url("/apis/auth"))
    else: # User has successfully logged in.  Confirm to script
      self.response.headers['Content-Type'] = "text/plain"
      user = users.get_current_user()
      admin = rcAdmin.get_or_insert(key_name=user.nickname(), userAcct=user, userChar=user.nickname())
      
      self.response.out.write('1:%s' % admin.userChar)